<template>
  <div class="image-gallery">
    <template v-if="type === 'shot'">
      <div class="image" v-for="(item,index) in srcs" :key="item.toString()">
        <el-image
          class="img-box-gallery"
          :src="item"
          :preview-src-list="srcs"
        ></el-image>
        <img class="del-pic" src="@/assets/del-pic2.png" @click="delPic(index)"/>
      </div>
      <label for="add-pic" v-if="srcs.length <= 4">
        <img class="add-pic" src="@/assets/add-pic.png" alt="add-pic"/>
      </label>
      <input
        id="add-pic"
        type="file"
        accept="image/png, image/jpeg, image/jpg"
        style="display: none"
        multiple
        @change="handlePicChange($event)"
      />
    </template>
    <template v-else>
      <div class="image" v-for="item in srcs" :key="item.toString()">
        <el-image
          class="img-box-gallery"
          :src="item"
          :preview-src-list="srcs"
        ></el-image>
      </div>
    </template>
  </div>
</template>

<script>
export default {
  name: "ImageGallery",
  props: ["srcs", "type"],

  // type: show || shot
  data() {
    return {};
  },

  computed: {},
  methods: {
    handlePicChange(e) {
      this.$emit("change", e);
    },
    delPic(i) {
        this.$emit("delete", i);
    }
  },
};
</script>

<style>
.image-gallery {
    display: flex;
}
.img-box-gallery,
.add-pic {
  width: 100px;
  height: 100px;
  border-radius: 10px;
  margin-right: 10px;
  cursor: pointer;
}

.image {
  position: relative;
}
.del-pic {
  position: absolute;
  height: 20px;
  width: 20px;
  right: 5px;
  top: -5px;
  cursor: pointer;
}
</style>